[Django] How do I filter the choices in a ModelForm that has a CharField with the choices attribute

Posted by nubela on Stack Overflow See other posts from Stack Overflow or by nubela
Published on 2009-07-22T16:52:44Z Indexed on 2010/06/15 5:02 UTC
Read the original article Hit count: 150

Filed under:
|

I understand I am able to filter queryset of Foreignkey or Many2ManyFields, however, how do I do that for a simple CharField that is a Select Widget (Select Tag).

For example:

PRODUCT_STATUS = (
                  ("unapproved", "Unapproved"),
                  ("approved", "Listed"),
                  #("Backorder","Backorder"),
                  #("oos","Out of Stock"),
                  #("preorder","Preorder"),
                  ("userdisabled", "User Disabled"),
                  ("disapproved", "Disapproved by admin"),
                  )

and the Field:

o_status = models.CharField(max_length=100, choices=PRODUCT_STATUS, verbose_name="Product Status", default="approved")

Suppose I wish to limit it to just "approved" and "userdisabled" instead showing the full array (which is what I want to show in the admin), how do I do it?

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about django